package com.example.newspublish.util;

import com.example.newspublish.pojo.result.Result;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import cn.hutool.json.JSONUtil;
import java.io.IOException;

import static com.example.newspublish.pojo.result.ResultCodeEnum.AUTHEN_ERROR;

/**
 * response 响应工具类
 */
public class ResponseUtils {

    /**
     * 异常消息返回(适用过滤器中处理异常响应)
     *
     * @param response
     *
     */
    public static void writeErrMsg(HttpServletResponse response) throws IOException {
        response.setContentType(MediaType.APPLICATION_JSON_VALUE);
        response.setCharacterEncoding("UTF-8");
        response.getWriter().print(JSONUtil.toJsonStr(Result.build(response,AUTHEN_ERROR)));
    }


}